﻿/**
 * Opens a one-way streaming connection between Flash Media Interactive Server and a remote Flash Media Interactive
 * Server through a NetConnection object. A NetStream object is a channel inside a NetConnection object; call
 * NetStream.publish()  to publish data over this channel. Unlike a client-side NetStream object, a server-side
 * NetStream object can only publish data; it cannot subscribe to a publishing stream or play a recorded stream.
 * 
 * @author waneck
 */

package asc.net;
import asc.Stream;

extern class NetStream 
{
	/**
	 * Read-only; indicates the number of seconds assigned to the buffer by the NetStream.setBufferTime() method.
	 */
	var bufferTime(default, null):Int;
	
	/**
	 * Read-only; indicates the number of seconds the stream has been publishing. This is a good indication of 
	 * whether data is flowing from the source that has been set in a call to the NetStream.attach()  method.
	 */
	var time(default, null):Int;

	/**
	 * Creates a stream that can be used for publishing (sending) data through the specified NetConnection object. 
	 * However, you can create multiple streams that run simultaneously over the same connection.
	 * @param	connection	A NetConnection object.
	 */
	public function new(connection:NetConnection):Void;
	
	/**
	 * Attaches a data source to the NetStream object. 
	 * @param	stream	A Stream object. If you pass false, the attached Stream object detaches from the NetStream object.
	 * @return	A boolean value. If the attached object is a valid data source, true; otherwise, false.
	 */
	function attach(stream:Stream):Bool;
	
	/**
	 * Invoked every time a status change or error occurs in a NetStream object. The remote server can accept or reject
	 * a call to NetStream.publish().
	 * 
	 * @param	infoObject	An Object with code and level  properties that provide information about the status 
	 * 						of a NetStream call. Both properties are strings. 
	 * @see		asc.enums.NetStreamStatus
	 */
	function onStatus(infoObject: { code:String, level:String } ):Void;
	
	/**
	 * Publishes a stream to a remote server. Check the status in the NetStream.onStatus() handler to make sure
	 * that the remote server has accepted the publisher. If the stream has been published by another client, the
	 * publish() call can fail when it reaches the remote server. In this case, the remote server sends a status 
	 * message of "NetStream.Publish.BadName"  to the NetStream.onStatus() method.
	 * 
	 * @param	name			    A string identifying the stream to publish. If you pass false,
	 * 								the stream stops publishing. Use the following syntax: 
	 * 								FLV - ns.publish("filename")
	 * 								MP3 - ns.publish("mp3:filename")
	 * 								MP4 - ns.publish("mp4:filename.f4v")
	 * @param	?howToPublish		Valid values are "record", "append", and "live". The default value is "live". 
	 * 								If you omit this parameter or pass "live", live data is published but not recorded.
	 * 								If a file with this name already exists on the remote server, it is deleted.
	 * 								If you pass "record", the stream is published and the data is recorded to a new file. 
	 * 								If the file exists, it is overwritten. If you pass "append", the stream is published and the 
	 * 								data is appended to the existing stream specified by name. If no file is found, it is created. 
	 */
	function publish(name:String, ?howToPublish:String):Void;
	
	/**
	 * Broadcasts a data message over a stream. 
	 * @param	handlerName	A string that identifies the name of the handler to receive the message.
	 * @param	?p1...?p6	Optional parameters of any type. They are serialized and sent over the connection.
	 * 						The receiving handler receives them in the same order.
	 * @return	A boolean value; true if the data message is dispatched; otherwise, false. 
	 */
	function send(handlerName:String, ?p1:Dynamic, ?p2:Dynamic, ?p3:Dynamic, ?p4:Dynamic, ?p5:Dynamic, ?p6:Dynamic):Bool;
	
	/**
	 * Sets the size of the outgoing buffer in seconds. If publishing, it controls the buffer in the local server.
	 * @param	bufferTime	    A number indicating the size of the outgoing buffer in seconds.
	 */
	function setBufferTime(bufferTime:Int):Void;
	
	
}